#include "IfExp.h"
#include "IVisitor.h"

IfExp::IfExp(const exprTypePtr& test, const exprTypePtr& body, const exprTypePtr& orelse, int nodeId):
    exprType(nodeId),
    _test(test),
    _body(body),
    _orelse(orelse)
{
}
    
IfExp::~IfExp()
{
    
}
    
QString IfExp::type() const
{
    return "IfExp";
}
    

exprTypePtr IfExp::test()
{
    return _test;
}

void IfExp::setTest(const exprTypePtr& test)
{
    _test = test;
}

exprTypePtr IfExp::body()
{
    return _body;
}

void IfExp::setBody(const exprTypePtr& body)
{
    _body = body;
}

exprTypePtr IfExp::orelse()
{
    return _orelse;
}

void IfExp::setOrelse(const exprTypePtr& orelse)
{
    _orelse = orelse;
}

    
QString IfExp::toString() const
{
    return QString("IfExp[test=%1, body=%2, orelse=%3]").
                arg(_test ? _test->toString():"").
                arg(_body ? _body->toString():"").
                arg(_orelse ? _orelse->toString():"");
}
    
void IfExp::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitIfExp(node.dynamicCast<IfExp>());
}
    
void IfExp::traverse(IVisitor* visitor)
{
    if (_test != NULL)
        _test->accept(visitor, _test);
    if (_body != NULL)
        _body->accept(visitor, _body);
    if (_orelse != NULL)
        _orelse->accept(visitor, _orelse);
}